<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragments :: header(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客新增</title>
</head>
<body>
<!--导航-->
<nav th:replace="_fragments :: adminNavBar(1)"></nav>

<br>
<br>

<!--中间内容-->
<div class="m-container m-padded-tb-2">
    <div class="container">
        <div class="ui negative message" th:unless="${#strings.isEmpty(message)}" th:text="${message}"></div>
        <form id="blogForm" th:action="@{/admin/saveBlog}" method="post" class="ui form">
            <input type="hidden" name="published">

            <div class="required field">
                <div class="ui left labeled input">
                    <div class="ui selection compact blue basic dropdown label">
                        <input type="hidden" value="原创" name="flag">
                        <i class="dropdown icon"></i>
                        <div class="text"></div>
                        <div class="menu">
                            <div class="item" data-value="原创">原创</div>
                            <div class="item" data-value="转载">转载</div>
                            <div class="item" data-value="翻译">翻译</div>
                        </div>
                    </div>
                    <input type="text" name="title" placeholder="标题">
                </div>
            </div>

            <div class="required field">
                <!--editorMarkdown集成-->
                <div id="md-content" style="z-index: 1 !important;">
                    <textarea name="content" placeholder="博客内容" style="display: none"></textarea>
                </div>
            </div>

            <div class="two fields">
                <div class="required field">
                    <div class="ui left labeled action input">
                        <label class="ui compact blue basic label">分类</label>
                        <div class="ui fluid selection dropdown">
                            <input type="hidden" name="type.id">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div th:each="type : ${types}" class="item" th:data-value="${type.id}"
                                     th:text="${type.name}"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="required field">
                    <div class="ui left labeled action input">
                        <label class="ui compact blue basic label">标签</label>
                        <div class="ui fluid multiple search selection dropdown">
                            <input type="hidden" name="tagIds">
                            <i class="dropdown icon"></i>
                            <div class="default text">标签</div>
                            <div class="menu">
                                <div th:each="tag : ${tags}" class="item" th:data-value="${tag.id}"
                                     th:text="${tag.name}"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="required field">
                <div class="ui left labeled input">
                    <label class="ui blue basic label">首图</label>
                    <input type="text" name="coverPicture" placeholder="首图引用地址">
                </div>
            </div>

            <div class="required field">
                <textarea name="description" placeholder="博客描述..." maxlength="200"></textarea>
            </div>

            <div class="inline fields">
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommendEnable" name="recommendEnable" checked class="hidden">
                        <label for="recommendEnable">推荐</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="shareStatementEnable" name="shareStatementEnable" checked
                               class="hidden">
                        <label for="shareStatementEnable">转载声明</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="appreciationEnable" name="appreciationEnable" checked class="hidden">
                        <label for="appreciationEnable">赞赏</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="commentEnable" name="commentEnable" checked class="hidden">
                        <label for="commentEnable">评论</label>
                    </div>
                </div>
            </div>

            <div class="ui error message"></div>

            <div class="ui right aligned container">
                <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                <button type="button" id="saveBtn" class="ui secondary button">保存</button>
                <button type="button" id="publishBtn" class="ui red button">发布</button>
            </div>
        </form>
    </div>
</div>

<br>
<br>
<br>
<br>
<br>
<br>

<script>
    // editorMarkdown初始化
    var contentEditor;
    $(function () {
        contentEditor = editormd("md-content", {
            width: "100%",
            height: 640,
            syncScrolling: "single",
            emoji: true,
            // path: "../../static/lib/editormd/lib/"
            path: "/lib/editormd/lib/"
        });
    });


    $(".menu.toggle").click(function () {
        $(".m-item").toggleClass("m-mobile-hide")
    });

    $(".ui.dropdown").dropdown()

    $(".ui.form").form({
        fields: {
            title: {
                identifier: "title",
                rules: [{
                    type: "empty",
                    prompt: "请输入博客标题"
                }]
            },
            content: {
                identifier: "content",
                rules: [{
                    type: "empty",
                    prompt: "请输入博客内容"
                }]
            },
            typeId: {
                identifier: "type.id",
                rules: [{
                    type: "empty",
                    prompt: "请选择博客分类"
                }]
            },
            tagIds: {
                identifier: "tagIds",
                rules: [{
                    type: "empty",
                    prompt: "请选择至少一个博客标签"
                }]
            },
            coverPicture: {
                identifier: "coverPicture",
                rules: [{
                    type: "empty",
                    prompt: "请输入博客封面地址"
                }]
            },
            description: {
                identifier: "description",
                rules: [{
                    type: "empty",
                    prompt: "请输入博客描述"
                }]
            },
        }
    })

    $("#saveBtn").click(function () {
        $("[name='published']").val(false)
        $("#blogForm").submit()
    })
    $("#publishBtn").click(function () {
        $("[name='published']").val(true)
        $("#blogForm").submit()
    })
</script>
</body>
</html>
